package varvelworld.algorithm.DuplicationFinding;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JDKHashMap implements IDuplicationFinding {

    @Override
    public List<Long> execute(long[] a) {
        List<Long> result = new ArrayList<Long>();
        Map<Long, Integer> map = new HashMap<Long, Integer>();
        for(int i = 0; i < a.length; i++){
            Integer sum = map.get(a[i]);
            if(sum == null){
                map.put(a[i], 1);
            }
            else{
                map.put(a[i], sum++);
                if(sum == 2){
                    result.add(a[i]);
                }
            }
        }
        return result;
    }
    


}
